package com.sikaryofficial.backend.service.points;

import com.sikaryofficial.backend.constant.RedisCacheKey;
import com.sikaryofficial.backend.service.IPointsDetailStrategy;
import com.sikaryofficial.common.core.constant.PointRuleConstant;
import org.springframework.stereotype.Service;

/**
 * @author : qinjinyuan
 * @desc : 文章收到的点赞服务
 * @date : 2023/10/31 19:03
 */
@Service(value = PointRuleConstant.ARTICLE_RECEIVED_LIKE + IPointsDetailStrategy.SUFFIX)
public class ArticleReceivedLikeService extends AbstractPointService {
    /**
     * 增加积分后校验
     *
     * @param userId
     * @return
     */
    @Override
    public boolean updatePoints(Long sourceId,Long userId) {
        // 自助评价，当积分大于上限，则不继续增加积分
        boolean isOver = checkPointsOver(userId,PointRuleConstant.ARTICLE_RECEIVED_LIKE, RedisCacheKey.ARTICLE_RECEIVED_LIKE_POINTS_NUM);
        if(!isOver){
            // 没有超，则可以继续更新积分
            this.increasePoints(sourceId,userId,PointRuleConstant.ARTICLE_RECEIVED_LIKE, "");
            // 增加后，进行统计缓存设置
            this.afterIncrease(userId, RedisCacheKey.ARTICLE_RECEIVED_LIKE_POINTS_NUM);
        }
        return false;
    }
}
